package cn.edu.baiyunu.myapplication.data

import cn.edu.baiyunu.myapplication.data.model.Category
import cn.edu.baiyunu.myapplication.data.model.Transaction
import java.util.Calendar
import java.util.UUID

/**
 * 测试数据生成工具，用于初始化应用中的默认数据
 */
object TestDataGenerator {
    
    /**
     * 获取默认支出分类列表
     */
    fun getDefaultExpenseCategories(): List<Category> {
        return listOf(
            Category(
                id = UUID.randomUUID().toString(),
                name = "餐饮",
                icon = "food",
                type = "expense",
                orderIndex = 0
            ),
            Category(
                id = UUID.randomUUID().toString(),
                name = "购物",
                icon = "shopping",
                type = "expense",
                orderIndex = 1
            ),
            Category(
                id = UUID.randomUUID().toString(),
                name = "交通",
                icon = "taxi",
                type = "expense",
                orderIndex = 2
            ),
            Category(
                id = UUID.randomUUID().toString(),
                name = "住房",
                icon = "home",
                type = "expense",
                orderIndex = 3
            ),
            Category(
                id = UUID.randomUUID().toString(),
                name = "医疗",
                icon = "medical",
                type = "expense",
                orderIndex = 4
            ),
            Category(
                id = UUID.randomUUID().toString(),
                name = "教育",
                icon = "education",
                type = "expense",
                orderIndex = 5
            )
        )
    }
    
    /**
     * 获取默认收入分类列表
     */
    fun getDefaultIncomeCategories(): List<Category> {
        return listOf(
            Category(
                id = UUID.randomUUID().toString(),
                name = "工资",
                icon = "salary",
                type = "income",
                orderIndex = 0
            ),
            Category(
                id = UUID.randomUUID().toString(),
                name = "奖金",
                icon = "celebration",
                type = "income",
                orderIndex = 1
            ),
            Category(
                id = UUID.randomUUID().toString(),
                name = "投资",
                icon = "insights",
                type = "income",
                orderIndex = 2
            ),
            Category(
                id = UUID.randomUUID().toString(),
                name = "转账",
                icon = "bank",
                type = "income",
                orderIndex = 3
            )
        )
    }
    
    /**
     * 生成样本交易数据
     */
    fun generateSampleTransactions(
        expenseCategories: List<Category>,
        incomeCategories: List<Category>
    ): List<Transaction> {
        val transactions = mutableListOf<Transaction>()
        val calendar = Calendar.getInstance()
        
        // 生成本月的几笔支出记录
        if (expenseCategories.isNotEmpty()) {
            // 餐饮支出
            transactions.add(
                Transaction(
                    id = UUID.randomUUID().toString(),
                    type = "expense",
                    amount = 50.0,
                    categoryId = expenseCategories[0].id,
                    date = calendar.timeInMillis,
                    note = "午餐"
                )
            )
            
            // 日历前移一天
            calendar.add(Calendar.DAY_OF_MONTH, -1)
            
            // 购物支出
            transactions.add(
                Transaction(
                    id = UUID.randomUUID().toString(),
                    type = "expense",
                    amount = 200.0,
                    categoryId = expenseCategories[1].id,
                    date = calendar.timeInMillis,
                    note = "超市购物"
                )
            )
            
            // 日历前移一天
            calendar.add(Calendar.DAY_OF_MONTH, -1)
            
            // 交通支出
            transactions.add(
                Transaction(
                    id = UUID.randomUUID().toString(),
                    type = "expense",
                    amount = 30.0,
                    categoryId = expenseCategories[2].id,
                    date = calendar.timeInMillis,
                    note = "打车"
                )
            )
        }
        
        // 生成本月的收入记录
        if (incomeCategories.isNotEmpty()) {
            // 重置日历到月初
            calendar.set(Calendar.DAY_OF_MONTH, 1)
            
            // 工资收入
            transactions.add(
                Transaction(
                    id = UUID.randomUUID().toString(),
                    type = "income",
                    amount = 5000.0,
                    categoryId = incomeCategories[0].id,
                    date = calendar.timeInMillis,
                    note = "月薪"
                )
            )
            
            // 日历移动到中旬
            calendar.set(Calendar.DAY_OF_MONTH, 15)
            
            // 奖金收入
            transactions.add(
                Transaction(
                    id = UUID.randomUUID().toString(),
                    type = "income",
                    amount = 1000.0,
                    categoryId = incomeCategories[1].id,
                    date = calendar.timeInMillis,
                    note = "绩效奖金"
                )
            )
        }
        
        return transactions
    }
} 